﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Finance.Querys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Finance.Accounts
{
    [RemoteService]
    [Route("api/v1/dimensions")]
    public class AccountDimensionController : BaseController
    {
        private IAccountDimensionAppService _appService;

        public AccountDimensionController(IAccountDimensionAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("all")]
        public async Task<List<AccountDimensionDto>> GetAllAsync(string keyword, bool? activated)
        {
            var pageResult = await _appService.FindAsync(new PageQuery() { Keyword = keyword, Activated = activated, PageIndex = 1, PageSize = int.MaxValue });

            var items = pageResult.Items;

            var result = items == null ? new List<AccountDimensionDto>() : items.ToList();

            return result;
        }


        [HttpGet]
        [Route("{id}")]
        public async Task<AccountDimensionDto> GetAsync(Guid id)
        {
            var result = await _appService.GetAsync(id);

            return result;
        }

        [HttpGet]
        public async Task<PagedResultDto<AccountDimensionDto>> GetPageAsync(PageQuery pageQuery)
        {
            var result = await _appService.FindAsync(pageQuery);

            return result;
        }

        [HttpPost]
        public async Task<AccountDimensionDto> CreateAsync(AccountDimensionCreateDto dimension)
        {
            var result = await _appService.CreateAsync(dimension);

            return result;
        }

        [HttpPut]
        public async Task<AccountDimensionDto> UpdateAsync(AccountDimensionUpdateDto dimension)
        {
            var result = await _appService.UpdateAsync(dimension);

            return result;
        }

        [HttpPut]
        [Route("{id}/status")]
        public async Task UpdateAsync(Guid id , ActivateDtoBase request)
        {
            request.Id = id;

            var result = await _appService.ChangeStatus(request);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            var result = await _appService.DeleteAsync(id);
        }
    }
}
